function [x,y,Fnew, Gnew, iter] = newtonIteration2(func, x0, y0, maxiter, maxi, eps1, eps2, eps3)
%  输入：变量x、y; 函数F; 迭代初值x0,x1,y0,y1 最大迭代次数maxi 精度要求epsilon
%  返回：迭代结果，迭代次数
global d2r
iter = 0; % 记录迭代次数
i = 0;
h = 0.01;
lambda = 1;
[F0, G0] = func(x0, y0);
x = x0;
y = y0;
Fnew = F0;
Gnew = G0;
if abs(F0) > eps1 || abs(G0) > eps2
    [F1, G1] = func(x0+h, y0);
    [F2, G2] = func(x0, y0+h);
    dF0 = (F1 - F0)/h;
    dF1 = (F2 - F0)/h;
    dG0 = (G1 - G0)/h;
    dG1 = (G2 - G0)/h;
    df = [dF0, dF1; dG0, dG1];
    xynew = [x0; y0] - lambda*(df\[F0; G0]);
    xnew = upperLowerLimit(xynew(1), 0, 60*d2r);
    ynew = upperLowerLimit(xynew(2), 0, 60*d2r);
    [Fnew, Gnew] = func(xnew, ynew);
    if abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3
        disp('abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3')
    elseif abs(Fnew) < eps1 && abs(Gnew) < eps2
        x = xnew;
        y = ynew;
        disp('abs(Fnew) < eps1 && abs(Gnew) < eps2')
    else
        while i <= maxi && (abs(Fnew) > abs(F0) || abs(Gnew) > abs(G0))
            disp('缩小步长参数')
            lambda = lambda/2;
            xynew = [x0; y0] - lambda*(df\[F0; G0]);
            xnew = upperLowerLimit(xynew(1), 0, 60*d2r);
            ynew = upperLowerLimit(xynew(2), 0, 60*d2r);
            [Fnew, Gnew] = func(xnew, ynew);
            i = i + 1;
        end
        if abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3
            disp('abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3')
        else
            while iter <= maxiter
                x0 = xnew;
                y0 = ynew;
                lambda = 1;
                [F0, G0] = func(x0, y0);
                [F1, G1] = func(x0+h, y0);
                [F2, G2] = func(x0, y0+h);
                dF0 = (F1 - F0)/h;
                dF1 = (F2 - F0)/h;
                dG0 = (G1 - G0)/h;
                dG1 = (G2 - G0)/h;
                df = [dF0, dF1; dG0, dG1];
                xynew = [x0; y0] - lambda*(df\[F0; G0]);
                xnew = upperLowerLimit(xynew(1), 0, 60*d2r);
                ynew = upperLowerLimit(xynew(2), 0, 60*d2r);
                [Fnew, Gnew] = func(xnew, ynew);
                i = 0;
                while i <= maxi && (abs(Fnew) > abs(F0) || abs(Gnew) > abs(G0))
                    disp('缩小步长参数')
                    lambda = lambda/2;
                    xynew = [x0; y0] - lambda*(df\[F0; G0]);
                    xnew = upperLowerLimit(xynew(1), 0, 60*d2r);
                    ynew = upperLowerLimit(xynew(2), 0, 60*d2r);
                    [Fnew, Gnew] = func(xnew, ynew);
                    i = i + 1;
                end
                if abs(Fnew) < eps1 && abs(Gnew) < eps2
                    x = xnew;
                    y = ynew;
                    disp('abs(Fnew) < eps1 && abs(Gnew) < eps2')
                    break;
                end
                if abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3
                    x = x0;
                    y = y0;
                    disp('abs(abs(Fnew) - abs(F0)) <= eps3 && abs(abs(Gnew) - abs(G0)) <= eps3')
                    break;
                end
                iter = iter + 1;
            end
        end
    end
end
end